package com.woniuxy.stage3demo.service.servicecai.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.caicai.UserBean;
import com.woniuxy.stage3demo.bean.caicai.UserInfoBean;
import com.woniuxy.stage3demo.bean.caicai.dto.UserBeanDTO;
import com.woniuxy.stage3demo.bean.caicai.vo.UserVO;
import com.woniuxy.stage3demo.bean.hpxbean.OrderBean;
import com.woniuxy.stage3demo.mapper.mappercai.UserMapper;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.service.servicecai.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional(readOnly = true)
@Service
public class UserServiceImpl implements IUserService {

    @Resource
    private UserMapper userMapper;

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    /**
     * 用户列表的筛选查询
     * @return
     */
    @Override
    public PageInfo<UserVO> findBySearch(PageRequest request, UserBeanDTO userBean) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->userMapper.findBySearch(request,userBean));
    }


    /**
     * 根据用户的Id查询用户的基本信息
     * @param id
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public UserBean findUserById(long id ) {
        return userMapper.findUserById(id);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public UserBean findUserById2(long id ) {
        return userMapper.findUserById2(id);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public UserBean findUserById3(long id ) {
        return userMapper.findUserById3(id);
    }



    /**
     * 根据用户的id修改用户的状态
     * @param id
     * @param
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateUserStatus(int opt, Long id) {
        return userMapper.updateUserStatus(opt,id);
    }
    /**
     * 根据id批量删除用户
     * @param
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int delMoreUser(Long id) {
        return userMapper.delMoreUser(id);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int delUser(long id) {
        return userMapper.delUser(id);
    }

    /**
     * 查询用户，配偶，担保人真实信息
     * @param
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public UserInfoBean findUserInfo(long id) {
        return userMapper.findUserInfo(id);
    }


    /**
     根据用户id查订单表
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public List<OrderBean> findOrderByUID(Long id) {

            return userMapper.findOrderByUID(id);

    }


}
